<template>
    <div>
        <!-- 搜索组件 -->
        <!-- <search-form :items="formItems" :params="params" :on-submit="onSearch" :btn-loading="loading" /> -->

        <!-- 表格区域 -->
        <div class="table-body">
            <!-- 左上角按钮 -->
            <div class="table-right-top"></div>

            <!-- 表格 -->
            <el-table border style="width: 100%;" :data="data" v-loading="loading">
                <el-table-column align="center" prop="month" :label="$i18n.t('MONTH_NAME')" :min-width="120" fixed="left"></el-table-column>
                <el-table-column align="center" prop="total" :label="$i18n.t('TOTAL')" :min-width="120" fixed="left"></el-table-column>
                <el-table-column align="center" prop="risk" :label="$i18n.t('RISK_SERVICE_FEE')" :min-width="130"></el-table-column>
                <el-table-column align="center" prop="order_pay" :label="$i18n.t('MAKE_LOAN_SERVICE_FEE')" :min-width="130"></el-table-column>
                <el-table-column align="center" prop="tel" :label="$i18n.t('TEL_SERVICE_FEE')" :min-width="130"></el-table-column>
                <el-table-column align="center" prop="sms" :label="$i18n.t('SMS_SERVICE_FEE')" :min-width="130"></el-table-column>
                <el-table-column align="center" prop="face" :label="$i18n.t('FACE_SERVICE_FEE')" :min-width="130"></el-table-column>
                <el-table-column align="center" prop="ocr" :label="$i18n.t('OCR_SERVICE_FEE')" :min-width="130"></el-table-column>
                <el-table-column align="center" prop="living" :label="$i18n.t('LIVING_SERVICE_FEE')" :min-width="130"></el-table-column>
                <el-table-column align="center" prop="identity_auth" :label="$i18n.t('IDENTITY_AUTH_SERVICE_FEE')" :min-width="130"></el-table-column>

            </el-table>

            <!-- 分页 -->
            <div class="table-pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next, ->, sizes"
                    :page-size.sync="page.perPage"
                    :total="page.total"
                    :page-count="page.pageCount"
                    :current-page.sync="page.currentPage"
                    :page-sizes="PAGES_SIZE"
                    @current-change="onCurrentPageChange"
                    @size-change="onPerPageChange"
                >
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
    // import SearchForm from '@/components/SearchForm'
    import { getFinance } from '@/api/charge'
    import { PAGES_SIZE } from '@/config/constants'

    export default {
        name: 'chargeFinance',
        // components: { SearchForm },
        data () {
            return {
                PAGES_SIZE,
                params: {},
                data: [],
                page: {
                    total: 0,
                    currentPage: 1,
                    perPage: PAGES_SIZE[0],
                    pageCount: 1
                },
                loading: false,
                drawer: false,
                mdl: {}
            }
        },
        created () {
            this.fetch()
        },
        computed: {
            formItems () {
                // 构建搜索表单
                return []
            }
        },
        methods: {
            // 搜索按钮
            onSearch () {
                this.fetch()
            },
            // 从接口拉取数据
            fetch () {
                this.loading = true
                getFinance({ ...this.params, page: this.page.currentPage, perPage: this.page.perPage }).then((res) => {
                    // eslint-disable-next-line camelcase
                    const { data, last_page, total } = res.result
                    this.data = data
                    this.page.total = total
                    // eslint-disable-next-line camelcase
                    this.page.pageCount = last_page
                }).finally(() => {
                    this.loading = false
                })
            },
            // 页数切换
            onCurrentPageChange (page) {
                this.page.currentPage = page
                this.fetch()
            },
            // 每页显示数量修改
            onPerPageChange (perPage) {
                this.page.perPage = perPage
                this.fetch()
            }
        }
    }
</script>

<style lang="less" scoped>
</style>
